import http from '../utils/http'
import qs from 'qs'


const params = qs.parse(window.location.hash.replace(/.+\?/, ''))

const get = (url, param) => http.get(`http://api.hrchildren.com/index.php?s=/Api/${url}`, Object.assign({}, param))

const SelectAllBeautifulGrain = () => get('SelectAllBeautifulGrain', {

})

const getApiInfo = () => get('SaveDataBeautifulGrain', {
  id: params.id
})


const getWxSdk = (url, res) => http.post('Zmhf/index', {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  type: "getJSSDKdata",
  sign: res,
  url
})

////////////////
// add.vue 页面 //
////////////////

/**
 * 调取省接口
 * @param  {string} res signbase
 * @return {void}
 */
const getTheProvince = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getRegionList",
  data: {
    region_id: 0,
    region_type: "prov"
  }
})


/**
 * 保存收货地址
 * @param  {string} res        signbase
 * @param  {number} shengId    省
 * @param  {number} shiId      市
 * @param  {number} quId       地区
 * @param  {number} jiedaoId   街道
 * @param  {string} AllAddress 详细
 * @param  {string} alladdress 省市地区街道全
 * @param  {string} name       姓名
 * @param  {number} phone      手机号码
 * @return {void}
 */
const saveAddAddress = (res, shengId, shiId, quId, jiedaoId, AllAddress, alladdress, name, phone) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "addAddress",
  data: {
    prov: shengId, //省
    city: shiId, //市
    area: quId, //地区
    town: jiedaoId, //街道
    detail: AllAddress, //详细
    address: alladdress, //省市地区街道全
    contact: name, //姓名
    mobile: phone //手机号码
  }
})


/**
 * 选择省调取接口
 * @param  {string} res        signbase
 * @param  {number} id  省编码
 * @return {void}
 */
const getRegionListCity = (res, id) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getRegionList",
  data: {
    region_id: id,
    region_type: "city"
  }
})


/**
 * 选择城市调取接口
 * @param  {string} res        signbase
 * @param  {number} id  市编码
 * @return {void}
 */
const getRegionListDistrict = (res, id) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getRegionList",
  data: {
    region_id: id,
    region_type: "district"
  }
})

//////////////////////
// address.vue 页面接口 //
//////////////////////

/**
 * 调用地址列表
 * @param  {string} res        signbase
 * @return {void}
 */
const getAddressList = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getAddressList",
  data: {}
})


/**
 * 调用默认地址列表
 * @param  {string} res        signbase
 * @return {void}
 */
const getUserAddressid = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getUserAddressid",
  data: {}
})


/**
 * 设置默认地址
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @return {void}
 */
const setUserAddressid = (res, addressId) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "setUserAddressid",
  data: {
    addressid: addressId
  }
})


/**
 * 删除地址
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @return {void}
 */
const delAddress = (res, addressId) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "delAddress",
  data: {
    address_id: addressId
  }
})

////////////////
// gift.vue页面 //
////////////////

/**
 * 初始或领取礼包数据
 * @param  {string} sign        signbase
 * @param  {string} secretKey   密匙
 * @param  {string} getInitGift 初始化礼物
 * @return {void}
 */
const getInitGift = (sign, secretKey, getInitGift) => http.post("Zmhf/index", {
  sign: sign,
  key: secretKey,
  type: getInitGift
})


/**
 * 获取轮播数据
 * @param  {string} sign        signbase
 * @param  {string} secretKey   密匙
 * @param  {string} getLogList  获取轮播数据
 * @return {void}
 */
const getLogList = (sign, secretKey, getLogList) => http.post("Zmhf/index", {
  sign: sign,
  key: secretKey,
  type: getLogList
})


/**
 * 获取礼物
 * @param  {string} sign        signbase
 * @param  {string} secretKey   密匙
 * @param  {string} setUserGift 获取用户礼物
 * @param  {string} id          用户ID
 * @param  {string} name        用户名字
 * @return {void}
 */
const setUserGift = (sign, secretKey, setUserGift, id, name) => http.post("Zmhf/index", {
  key: secretKey,
  type: setUserGift,
  sign: sign,
  data: {
    gift_id: id,
    gift_name: name
  }
})

///////////////////////
// historical.vue 页面 //
///////////////////////


/**
 * 选择赛区接口1
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @return {void}
 */
const selectList1SortData = (res, addressId) => http.post("Zmhf/index", {
  data: {
    division_id: addressId,
    sortlist_type: 2
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectListSortData"
})


/**
 * 选择赛区接口2
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @return {void}
 */
const selectList2SortData = (res, addressId) => http.post("Zmhf/index", {
  data: {
    division_id: addressId,
    sortlist_type: 3
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectListSortData"
})


/**
 * 时间榜单1
 * @param  {string} res        signbase
 * @return {void}
 */
const selectLog2TimeData = (res) => http.post("Zmhf/index", {
  data: {
    sortlist_type: 2
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectLogTimeData"
})


/**
 * 时间榜单2
 * @param  {string} res        signbase
 * @return {void}
 */
const selectLog1TimeData = (res) => http.post("Zmhf/index", {
  data: {
    sortlist_type: 3
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectLogTimeData"
})


/**
 * 历史榜单接口1
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @param  {string} timeId    选择的时间
 * @return {void}
 */
const selectList2SortDataLog = (res, addressId, timeId) => http.post("Zmhf/index", {
  data: {
    division_id: addressId, //赛区Id
    sortlist_type: 3, //榜单类型
    weektime_id: timeId //选择时间_id
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectListSortDataLog"
})


/**
 * 历史榜单接口1
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @param  {string} timeId    选择的时间
 * @return {void}
 */
const selectList1SortDataLog = (res, addressId, timeId) => http.post("Zmhf/index", {
  data: {
    division_id: addressId, //赛区Id
    sortlist_type: 2, //榜单类型
    weektime_id: timeId //选择时间_id
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectListSortDataLog"
})


/**
 * 地区下拉列表
 * @param  {string} res        signbase
 * @return {void}
 */
const selectDivisionData = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectDivisionData"
})


/////////////////
// index.vue接口 //
/////////////////

/**
 * 初始化用户数据
 * @param  {string} res        signbase
 * @return {void}
 */
const selectAllBeautifulGrainOne = (res) => http.post("Zmhf/index", {
  data: {
    sorttype: 1
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectAllBeautifulGrain"
})

/**
 * 点击显示最新参赛
 * @param  {string} res        signbase
 * @return {void}
 */
const selectAllBeautifulGrain = (res) => http.post("Zmhf/index", {
  data: {
    sorttype: 1,
    length: 6,
    page: 1
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectAllBeautifulGrain"
})


/**
 * 初始化最新赛数据第一页
 * @param  {string} res        signbase
 * @return {void}
 */
const selectCandidatesDataOne = (res) => http.post("Zmhf/index", {
  data: {
    sorttype: 1,
    length: 6,
    page: 1
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectCandidatesData"
})


/**
 * 下拉加载数据
 * @param  {string} res        signbase
 * @param  {number} pageNumNew 最新页数
 * @return {void}
 */
const selectCandidatesData = (res, pageNumNew) => http.post("Zmhf/index", {
  data: {
    sorttype: 1,
    length: 6,
    page: pageNumNew
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectCandidatesData"
})


/**
 * 搜索参赛数据
 * @param  {string} res        signbase
 * @param  {string|number} search 名字或ID
 * @return {void}
 */
const searchCandidatesData = (res, search) => http.post("Zmhf/index", {
  data: {
    sorttype: 1,
    search: search,
    page: 1
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectCandidatesData"
})

////////////////
// List.vue接口 //
////////////////


/**
 * 选择赛区接口3
 * @param  {string} res        signbase
 * @param  {string} addressId  地址id
 * @return {void}
 */
const selectList3SortData = (res, addressId) => http.post("Zmhf/index", {
  data: {
    division_id: addressId,
    sortlist_type: 1
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectListSortData"
})


////////////////
// mine.vue接口 //
////////////////


/**
 * 获取用户注册信息
 * @param  {string} res        signbase
 * @return {void}
 */
const selectMyListData = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectMyListData"
})


/**
 * 获取用户奖券信息
 * @param  {string} res        signbase
 * @return {void}
 */
const getUserTicketList = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getUserTicketList"
})


/**
 * 获取用户奖品信息
 * @param  {string} res        signbase
 * @return {void}
 */
const beautifulactionDrawPrizeLog = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "BeautifulactionDrawPrizeLog"
})

/**
 * 用户参赛注册资格验证
 * @param  {string} res        signbase
 * @return {void}
 */
const judgeisRegister = (res) => http.post("Zmhf/index", {
  // candidates_id: this.$route.query.candidates_id
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "JudgeisRegister"
})

//////////////
// personal.vue接口 //
//////////////

/**
 * 获取参赛选手信息
 * @param  {string} res        signbase
 * @param  {srting} candidates_id 用户ID
 * @return {void}
 */
const selectMyInfoBeautifulGrain = (res, candidates_id) => http.post("Zmhf/index", {
  data: {
    candidates_id: candidates_id
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectMyInfoBeautifulGrain"
})

/**
 * 获取顶部投票数据
 * @param  {string} res        signbase
 * @param  {srting} candidates_id 用户ID
 * @return {void}
 */
const selectlaterVoteLog = (res, candidates_id) => http.post("Zmhf/index", {
  data: {
    candidates_id: candidates_id
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SelectlaterVoteLog"
})

/**
 * 获取抽奖信息
 * @param  {string} res        signbase
 * @param  {srting} candidates_id 用户ID
 * @return {void}
 */
const beautifulactionDrawPrize = (res, candidates_id) => http.post("Zmhf/index", {
  data: {
    candidates_id: candidates_id
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "BeautifulactionDrawPrize"
})

/**
 * 为参赛选手投票
 * @param  {string} res        signbase
 * @param  {srting} candidates_id 用户ID
 * @return {void}
 */
const saveVoteDataBeautifulGrain = (res, candidates_id, addressId) => http.post("Zmhf/index", {
  data: {
    candidates_id: candidates_id,
    division_id: addressId
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SaveVoteDataBeautifulGrain"
})


/////////////////
// sign.vue接口  //
/////////////////


/**
 * 验证用户是否注册账号
 * @param  {string} res        signbase
 * @return {void}
 */
const drawingBeautifulGrainData = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "DrawingBeautifulGrainData"
})


/**
 * 用户参赛注册
 * @param  {string} res         signbase
 * @param  {string} store       用户的使用描述
 * @param  {string} userNewName 用户注册时的姓名
 * @param  {string} avatar1     使用前照片
 * @param  {string} avatar2     使用后照片
 * @return {void}
 */
const saveDataBeautifulGrain = (res, store, userNewName, avatar1, avatar2) => http.post("Zmhf/index", {
  data: {
    // name: name,
    // mobile: phone,
    // division_id: division,
    // address: address,
    content: store,
    name: userNewName,
    before_image: avatar1,
    after_image: avatar2
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "SaveDataBeautifulGrain"
})

//////////////////
// ticket.vue接口 //
//////////////////

/**
 * 用户注册后生成的二维码信息
 * @param  {string} res         signbase
 * @param  {srting} candidates_id 用户ID
 * @return {void}
 */
const createSign = (res, candidates_id) => http.post("Zmhf/index", {
  data: {
    candidates_id: candidates_id
  },
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "createSign"
})

/////////////////
// Voucher.vue //
/////////////////

/**
 * 获取用户奖券信息
 * @param  {string} res         signbase
 * @return {void}
 */
/*const getUserTicketList = (res) => http.post("Zmhf/index", {
  key: "be15d4ca913c91494cb4f9cd6ce317c6",
  sign: res,
  type: "getUserTicketList"
})
*/
export {
  SelectAllBeautifulGrain,
  getApiInfo,
  getWxSdk,
  getTheProvince,
  saveAddAddress,
  getRegionListCity,
  getRegionListDistrict,
  getAddressList,
  getUserAddressid,
  setUserAddressid,
  delAddress,
  getInitGift,
  getLogList,
  setUserGift,
  selectList1SortData,
  selectList2SortData,
  selectLog2TimeData,
  selectLog1TimeData,
  selectList2SortDataLog,
  selectList1SortDataLog,
  selectDivisionData,
  selectAllBeautifulGrainOne,
  selectAllBeautifulGrain,
  selectCandidatesDataOne,
  selectCandidatesData,
  searchCandidatesData,
  selectList3SortData,
  selectMyListData,
  getUserTicketList,
  beautifulactionDrawPrizeLog,
  judgeisRegister,
  selectMyInfoBeautifulGrain,
  selectlaterVoteLog,
  beautifulactionDrawPrize,
  saveVoteDataBeautifulGrain,
  drawingBeautifulGrainData,
  saveDataBeautifulGrain,
  createSign
}